import React, { Component, Suspense } from 'react';
import { Route, Redirect, Switch } from 'react-router-dom'
 
class RouterView extends Component {
    render() { 
    const {routes=[]} = this.props
        return (
            <Suspense fallback={<div>loading...</div>}>
                <Switch>
                    {
                        routes.map((item,index)=>{
                            return  <Route 
                                key={index}
                                path={item.path} 
                                render={(historyProps)=>{
                                    return  item.redirect ? 
                                    <Redirect to={item.redirect} /> :
                                    <item.component {...historyProps} routes={item.children} />
                                }}
                            />
                        })
                    }
                </Switch>
            </Suspense>
        );
    }
}
 
export default RouterView;